package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitorInterface;

public class DECLARACIONFactory extends AbstractTokenVisitorFactory {

	private static DECLARACIONFactory INSTANCE;
	
	private DECLARACION1Factory declaracion1Factory;
	private DECLARACION2Factory declaracion2Factory;
	private BLOQUEFactory bloqueFactory;
	
	public static DECLARACIONFactory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new DECLARACIONFactory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() throws Exception {
			initializer = NoOperationInitializer.getInstance();
			declaracion1Factory = DECLARACION1Factory.getInstance();
			declaracion2Factory = DECLARACION2Factory.getInstance();
			bloqueFactory = BLOQUEFactory.getInstance();
		}
	};
	
	private DECLARACIONFactory() throws Exception {

	}
	
	@Override
	public TokenVisitorInterface makeChainedVisitor(
			final TokenVisitorInterface siguiente) throws Exception {
		initializer.init();

		return declaracion1Factory.makeChainedVisitor(declaracion2Factory.makeChainedVisitor(bloqueFactory.makeChainedVisitor(siguiente)));
	
	}
	@Override
	public TokenVisitorInterface makeVisitor() throws Exception {
		initializer.init();

		return declaracion1Factory.makeChainedVisitor(declaracion2Factory.makeChainedVisitor(bloqueFactory.makeVisitor()));
	}
	
	
}
